from media.sensor import *
from media.display import *
from media.media import *
import sys
import time


class Logo:
    
    def __init__(self, pipeline, logo_path="/sdcard/images/001.jpg"):
        """
        初始化Logo显示类
        
        参数:
            pipeline: PipeLine实例
            logo_path: Logo图片路径
        """
        self.pl = pipeline
        self.logo_path = logo_path
        self.logo_img = None
        
    def load_logo(self):
        """加载Logo图片"""
        try:
            self.logo_img = image.Image(self.logo_path)
            print(f"成功加载Logo: {self.logo_path}")
            return True
        except Exception as e:
            print(f"加载Logo失败: {e}")
            return False
    
    def draw_logo(self, duration=3):
        """
        显示Logo指定时间
        
        参数:
            duration: 显示时间(秒)
        """
        if not self.logo_img:
            if not self.load_logo():
                return
        
        # 获取显示尺寸
        display_width, display_height = self.pl.get_display_size()
        
        # 计算居中位置
        offset_x = (display_width - self.logo_img.width()) // 2
        offset_y = (display_height - self.logo_img.height()) // 2
        
        # 清除OSD层
        self.pl.osd_img.clear()
        
        # 将Logo绘制到OSD层
        self.pl.osd_img.draw_image(self.logo_img.to_rgb888(), offset_x, offset_y)
        
        # 显示Logo
        self.pl.show_image()
        
        # 等待指定时间
        print(f"显示Logo {duration}秒")
        time.sleep(duration)